import { getUserInfo } from '@/api/common/personal.js'
const app ={
  state: {
    sidebar: {
      opened: true,
      withoutAnimation: false,
    },
    isRegister: false,
    isMenuOpen: false,
    userInfo:  {},
    logoClick: false,
    isPhone: 0,
  },
  mutations:{
    TOGGLE_SIDEBAR: state =>{
      state.sidebar.opened = !state.sidebar.opened
    },
    TOGGLE_REGISTER: (state, data) =>{
      state.isRegister = data
    },
    TOGGLE_MENU_OPEN: (state, data) =>{
      state.isMenuOpen = data
    },
    TOGGLE_LOGO_CLICK: (state) =>{
      state.logoClick = !state.logoClick
    },
    TOGGLE_USERINFO: (state, data) =>{
      localStorage.setItem('userInfo', JSON.stringify(data))
      state.userInfo = data
    },
    TOGGLE_IS_PHONE: (state, data) =>{
      state.isPhone = data
    },
    
  },
  actions: {
    ToggleSideBar: ({ commit }) => {
      commit('TOGGLE_SIDEBAR')
    },
    ToggleRegister: ({ commit }, data) => {
      commit('TOGGLE_REGISTER', data)
    },
    ToggleMenuOpen: ({ commit }, data) => {
      commit('TOGGLE_MENU_OPEN', data)
    },
    ToggleUserInfo: ({ commit }, data) => {
      commit('TOGGLE_USERINFO', data)
    },
    ToggleLogoClick: ({ commit }) => {
      commit('TOGGLE_LOGO_CLICK')
    },
    ToggleIsPhone: ({ commit }) => {
      let data = window.screen.width  < 768
      commit('TOGGLE_IS_PHONE', data)
    },
    GetUserInfo: ({commit}) => {
      return new Promise(resolve => {
        getUserInfo().then(res=>{
          if(res.state ==1){
            if(res.data){
              commit('TOGGLE_USERINFO', res.data)
            }
            
          }
          // console.log(res, '当前登录用户信息获取')
        })
        resolve();
      })
    }
  }
}
export default app